<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/12/15
  Time: 15:43
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title><spring:message code='usercenter.index.title' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<jsp:include page="../public/header.jsp"></jsp:include>
<jsp:include page="../usercenter/leftMenu.jsp"></jsp:include>

<div class="member_box">
    <div class="member_title" id="member_title">
        <ul>
            <li stype="1" <c:if test="${type==1}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,1);changeTile(1);"><spring:message code='usercenter.collection.msg1' /></a></li>
            <li stype="2" <c:if test="${type==2}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,2);changeTile(2);"><spring:message code='usercenter.collection.msg2' /></a></li>
            <li stype="3" <c:if test="${type==3}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,3);changeTile(3);"><spring:message code='usercenter.collection.msg3' /></a></li>
            <li stype="4" <c:if test="${type==4}">class="hover"</c:if>><a href="javascript:void(0);" onclick="initBeanInfo(1,10,4);changeTile(4)"><spring:message code='usercenter.collection.msg4' /></a></li>
        </ul>
    </div>
    <div class="member_projectlist">
        <ul id="collection">
        </ul>
        <div  id="kkpager" style="text-align: center">
        </div>
    </div>
</div>
<link href="${path}/plugins/page/kkpager.css" rel="stylesheet">
<script src="${path}/plugins/page/kkpager.js" type="text/javascript"></script>
<script src="${path}/js/system.code.js" type="text/javascript"></script>
<script>
    var pageSize = 10;
    var type = '${type}';
    function changeTile(type){
        $("#member_title ul li").each(function(){
            if($(this).attr("stype")==type){
                $(this).addClass("hover");
            }else{
                $(this).removeClass("hover");
            }
        });
    }
    //收藏作品解析
    function templeate1(data){
        var list = data.pageInfo.list;
        var htmlstr = "";
        if (list != null) {
            for (var i = 0; i < list.length; i++) {
                var obj = list[i];
                if(obj.description == undefined){
                    obj.description='';
                }
                htmlstr+='<li class="clearfix">'+
                        '<div class="p_img"><a href="${path}/artistPersonalHome/browseProduction.html?production_id='+obj.workId+'"><img src="${path}/'+obj.cover+'" width="170" height="104"></a></div>'+
                        '<div class="p_con clearfix">'+
                        '<a href="${path}/artistPersonalHome/browseProduction.html?production_id='+obj.workId+'"><h3>'+obj.workName+'</h3></a>'+
                        '<div class="p_pcon">'+
                        '</div>'+
                        '<div class="p_money">'+
                        '<p><em class="price">￥'+obj.price+'</em></p>'+
                        '<p><em></em></p>'+
                        '</div>'+
                        '<div class="p_opr">'+
                        '<a href="javascript:void(0);"  onclick="deleteCollection('+obj.favoriteId+')"><spring:message code='usercenter.collection.msg5' /></a>'+
                        '</div>'+
                        '</div>'+
                        '<div class="clr"></div>'+
                        '</li>';
            }
            $("#collection").html(htmlstr);
            var pager = data.pageInfo;
            //分页
            createPage(pager.pageNum, pager.pages, pager.total,data.type);
        }
    }
    function templeate2(data){
        var list = data.pageInfo.list;
        var htmlstr = "";
        if (list != null) {
            for (var i = 0; i < list.length; i++) {
                var obj = list[i];
                if(obj.introSimplify == undefined){
                    obj.introSimplify='';
                }
                htmlstr+='<li class="clearfix">'+
                        '<div class="p_img"><a href="${path}/artistPersonalHome/artistPersonalHome.html?receiver='+obj.id+'"><img src="${path}/'+obj.avatar+'" width="170" height="104"></a></div>'+
                        '<div class="p_con clearfix">'+
                        '<a href="${path}/artistPersonalHome/artistPersonalHome.html?receiver='+obj.id+'"><h3>'+obj.nickname+'</h3></a>'+
                        '<div class="p_pcon">'+obj.introSimplify+
                        '</div>'+
                        '<div class="p_money">'+
                        '<p><em class="price"></em></p>'+
                        '<p><em>'+obj.artistLevel+'</em></p>'+
                        '</div>'+
                        '<div class="p_opr">'+
                        '<a href="javascript:void(0);"  onclick="deleteCollection('+obj.favoriteId+')"><spring:message code='usercenter.collection.msg5' /></a>'+
                        '</div>'+
                        '</div>'+
                        '<div class="clr"></div>'+
                        '</li>';
            }
            $("#collection").html(htmlstr);
            var pager = data.pageInfo;
            //分页
            createPage(pager.pageNum, pager.pages, pager.total,data.type);
        }
    }
    function templeate3(data){
        var list = data.pageInfo.list;
        var htmlstr = "";
        if (list != null) {
            for (var i = 0; i < list.length; i++) {
                var obj = list[i];
                if(obj.intro == undefined){
                    obj.intro='';
                }
                htmlstr+='<li class="clearfix">'+
                        '<div class="p_img"><a href="${path}/principal/principalView.html?principalId='+obj.baile_id+'"><img src="${path}/'+obj.avatar+'" width="170" height="104"></a></div>'+
                        '<div class="p_con clearfix">'+
                        '<a href="${path}/principal/principalView.html?principalId='+obj.baile_id+'"><h3>'+obj.nickname+'</h3></a>'+
                        '<div class="p_pcon">'+obj.intro+
                        '</div>'+
                        '<div class="p_money">'+
                        '<p><em class="price"></em></p>'+
                        '<p><em></em></p>'+
                        '</div>'+
                        '<div class="p_opr">'+
                        '<a href="javascript:void(0);"  onclick="deleteCollection('+obj.favoriteId+')"><spring:message code='usercenter.collection.msg5' /></a>'+
                        '</div>'+
                        '</div>'+
                        '<div class="clr"></div>'+
                        '</li>';
            }
            $("#collection").html(htmlstr);
            var pager = data.pageInfo;
            //分页
            createPage(pager.pageNum, pager.pages, pager.total,data.type);
        }
    }
    function templeate4(data){
        var list = data.pageInfo.list;
        var htmlstr = "";
        if (list != null) {
            for (var i = 0; i < list.length; i++) {
                var obj = list[i];
                if(obj.description == undefined){
                    obj.description='';
                }
                htmlstr+='<li class="clearfix">'+
                        '<div class="p_img"><a href="${path}/taskdetail/index.html?taskId='+obj.id+'"><img src="${path}/'+obj.pic+'" width="170" height="104"></a></div>'+
                        '<div class="p_con clearfix">'+
                        '<a href="${path}/taskdetail/index.html?taskId='+obj.id+'"><h3>'+obj.title+'</h3></a>'+
                        '<div class="p_pcon">'+obj.description+
                        '</div>'+
                        '<div class="p_money">'+
                        '<p><em class="price">￥'+obj.budget+'</em></p>'+
                        '<p><em>'+getOrderProgress(obj.progress)+'</em></p>'+
                        '</div>'+
                        '<div class="p_opr">'+
                        '<a href="javascript:void(0);" onclick="deleteCollection('+obj.favoriteId+')"><spring:message code='usercenter.collection.msg5' /></a>'+
                        '</div>'+
                        '</div>'+
                        '<div class="clr"></div>'+
                        '</li>';
            }
            $("#collection").html(htmlstr);
            var pager = data.pageInfo;
            //分页
            createPage(pager.pageNum, pager.pages, pager.total,data.type);
        }
    }
    //删除收藏
    function deleteCollection(id){
        if(confirm("<spring:message code='usercenter.collection.msg6' />")){
            $.post("${path}/usercenter/deleteCollection.html",{
                favoriteId:id
            },function(data){
                if(data.errormsg == undefined){
                    alert("<spring:message code='usercenter.collection.msg7' />");
                    initBeanInfo(1,10,type);
                }else{
                    alert(errormsg);
                }
            },"json");
        }
    }


    function initBeanInfo(page, rows,type) {
        //异步获取生产计划
        type = type;
        pageSize = rows;
        $.post("${path}/usercenter/getCollectionList.html", {
            page: page,
            rows: rows,
            type: type
        }, function (data) {

            switch (data.type){
                case 1:templeate1(data);break;
                case 2:templeate2(data);break;
                case 3:templeate3(data);break;
                case 4:templeate4(data);break;
                default : templeate1(data);break;
            }

        },"json");
    }

    //分页方法
    //currentPage 当前页
    //rows 每页条数
    //total 总数
    function createPage(currentPage, totalPage, totalCount,type) {
        var totalPage = totalPage;
        var totalRecords = totalCount;
        var pageNo = currentPage;
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //总数据条数
            totalRecords: totalRecords,
            //链接前部
            hrefFormer: 'index',
            //链接尾部
            hrefLatter: '',
            //是否显示总页数
            isShowTotalPage: true,
            //是否显示总记录数
            isShowTotalRecords: true,
            //是否显示页码跳转输入框
            isGoPage: true,
            //getLink: function (n) {
            //    return this.hrefFormer + this.hrefLatter + "?pno=" + n;
            //}
            //,
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                //this.selectpage(n);
                initBeanInfo(n, pageSize,type);
                return false;
            },
            lang				: {
                firstPageText			: '<spring:message code="firstPageText"/>',
                firstPageTipText		: '<spring:message code="firstPageTipText"/>',
                lastPageText			: '<spring:message code="lastPageText"/>',
                lastPageTipText			: '<spring:message code="lastPageTipText"/>',
                prePageText				: '<spring:message code="prePageText"/>',
                prePageTipText			: '<spring:message code="prePageTipText"/>',
                nextPageText			: '<spring:message code="nextPageText"/>',
                nextPageTipText			: '<spring:message code="nextPageTipText"/>',
                totalPageBeforeText		: '<spring:message code="totalPageBeforeText"/>',
                totalPageAfterText		: '<spring:message code="totalPageAfterText"/>',
                totalRecordsAfterText	: '<spring:message code="totalRecordsAfterText"/>',
                gopageBeforeText		: '<spring:message code="gopageBeforeText"/>',
                gopageButtonOkText		: '<spring:message code="gopageButtonOkText"/>',
                gopageAfterText			: '<spring:message code="gopageAfterText"/>',
                buttonTipBeforeText		: '<spring:message code="buttonTipBeforeText"/>',
                buttonTipAfterText		: '<spring:message code="buttonTipAfterText"/>'
            }
        },true);
    }
    $(function(){
        initBeanInfo(1,10,'${type}');
    });
</script>
<jsp:include page="../usercenter/leftMenuEnd.jsp"></jsp:include>
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>